<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class News_model extends CI_Model {

    function news_model() {
        parent::__construct();
    }

//------------Get All News(27.9.2012)----------
    function get_all_news($num=NULL, $offset=NULL) {
        $subcond = "where status=51";
        $limit = "";
        if (isset($num) && isset($offset))
            $limit = " limit $offset, $num";
        $sql = "select * from news " . $subcond . $limit;
        $query = $this->db->query($sql);
        $result = $query->result();
        return $result;
    }

//------------Get News by id(27.9.2012)----------    
    function get_news($id=NULL) {
        $sql = "select * from news where id=$id and status=51";
        $query = $this->db->query($sql);
        $row = $query->row();
        return $row;
    }

//------------Insert News(27.9.2012)----------   
    function insert_news($title=NULL, $detail=NULL, $meta_title=NULL, $meta_keyword=NULL, $meta_description=NULL) {
        $date = date('d-M-Y');
        $sql = "insert into news (title,description,date,meta_title,meta_keyword,meta_description) values('$title','$detail','$date','$meta_title','$meta_keyword','$meta_description')";
        $this->db->query($sql);
    }

//------------Update News(27.9.2012)----------       
    function update_news($id=NULL, $title=NULL, $detail=NULL, $meta_title=NULL, $meta_keyword=NULL, $meta_description=NULL) {
        $date = date('d-M-Y');
        $sql = "update news set `title`='$title',`description`='$detail',meta_title='$meta_title',meta_description='$meta_keyword',meta_description='$meta_description',`updated_on`='$date' where id='$id'";
        $this->db->query($sql);
    }

//------------Delete News(27.9.2012)----------   
    function delete_news($id=NULL) {
        $sql = "delete from news where id=$id";
        $this->db->query($sql);
    }
}
?>